function AjaxProxy() {

	function setAjaxDefaults( params ) {

		var ajaxParams = {
			type : 'GET',
			url : '',
			data : {}
		};

		if( params.type != undefined ) {
			$.extend( ajaxParams, {
				type : params.type
			});
		}

		if( params.url != undefined ) {
			$.extend( ajaxParams, {
				url : params.url
			});
		}

		if( params.data != undefined ) {
			$.extend(ajaxParams, {
				data : params.data
			});
		}

		return ajaxParams;
	}

	/***
	 * Handle an error coming from the server.
	 * using the status we can manage different actions, messages and so on.
	 * It can be completed for handling other errors or other use-cases as needed.
	 */
	function handleRejection( jqXHR ){
		switch ( jqXHR.status ) {
			case 403:
				console.log( jqXHR.status );
				return false;
				break;
			case 408:
				console.log( jqXHR.status );
				return false;
				break;
			case 500:
				console.log( jqXHR.status );
				return false;
				break;
			default:
				console.log( jqXHR.status );
				return true;
				break;
		}
	}

	function hasCompleteData( data ) {
		if( data.errorMsg != null ) {
			this.log( data.errorMsg )
			return false
		}
		return data.success && data.data != null;
	}

	/**
	 * Queue and make an ajax request, behaving exactly the same than jQuery $.ajax method
	 * 
	 * @param params
	 *            extends the set of key/value pairs that configure the Ajax
	 *            request (see http://api.jquery.com/jQuery.ajax/)
	 */
	this.doAjaxRequest = function( params ) {

		var ajaxParams = setAjaxDefaults( params );

		$.extend( ajaxParams, {
			success : function( data ) {
				if( $.isFunction( params.success ) ) {
					params.success( data );
				}
			},
			error : function( data ) {
				if( $.isFunction( params.error ) ) {
					params.error( data );
				}
			}
		});

		// Queue the ajax call
		$.ajax(ajaxParams);
	}

	/**
	 * Queue and make an ajax request, behaving exactly the same than jQuery $.ajax method
	 * 
	 * @param params
	 *            extends the set of key/value pairs that configure the Ajax
	 *            request (see http://api.jquery.com/jQuery.ajax/)
	 */
	this.doAjaxRestRequest = function( params ) {

		var ajaxParams = setAjaxDefaults( params );

		$.extend( ajaxParams, {
			success : function( data, textStatus, jqXHR ) {
				if( handleRejection( jqXHR ) ) {
					if( hasCompleteData( data ) ) {
						if( $.isFunction( params.success ) ) {
							params.success( data );
						}
					} else {
						if( $.isFunction( params.error ) ) {
							params.error( data );
						}
					}
				}
			},
			error : function( data, jqXHR ) {
				if( !handleRejection( jqXHR ) && $.isFunction( params.error ) ) {
					params.error( data );
				}
			}
		});

		// Queue the ajax call
		$.ajax(ajaxParams);
	}
}

var ajaxProxy = new AjaxProxy();